/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lenovo
 * Date: 2022-05-14
 * Time: 21:18
 */
class OuterClass{
    public int a;
    public int b;
    static int c=1;
    public OuterClass(){
        System.out.println("默认无参的构造方法被执行");
    }
    public void fun1(){
        System.out.println("外部类的成员方法被执行");
    }
    class InnerClass{
        public int c=111;
        public int d;
        public int e;
        public void fun2(){
            System.out.println("普通内部类的成员方法被执行");
            //实例内部类可以直接访问外部类的成员和方法
            a=10;
            b=20;
            fun1();
            //
            d=30;
            e=40;

            //当实例内部类与外部类的成员变量名相同时，优先访问内部类里的成员变量
            System.out.println("内部类"+c);
            //外部类类名.this.c
            System.out.println("外部类"+OuterClass.this.c);
        }
    }
    //外部类访问内部类时需要依赖内部类对象
  public void fun3(){
      InnerClass innerClass2 = new InnerClass();
      innerClass2.d=10;
  }
}
public class InnerClass {
    public static void main(String[] args) {
        OuterClass outerClass = new OuterClass();
        OuterClass.InnerClass innerClass = outerClass.new InnerClass();
      innerClass.fun2();

    }
}
